home *** CD-ROM | disk | FTP | other *** search
Wrap
<!-- #include file="i_utils.asp" --> <% check_security(1) %> <% dim Cat dim CatID dim CatTypeId dim Description dim ParentId dim RelatedId dim edit_cats_sql dim Parent dim CatType dim view_cats_sql sub request_edit_cats ''' request expected input parameters for this form Cat = request("Cat") CatID = request("CatID") CatTypeId = request("CatTypeId") Description = request("Description") ParentId = request("ParentId") RelatedId = request("RelatedId") end sub sub request_view_cats ''' request expected input parameters for this form Parent = request("Parent") ParentId = request("ParentId") CatID = request("CatID") Cat = request("Cat") RelatedId = request("RelatedId") CatType = request("CatType") end sub sub validate_edit_cats ''' request and validate data entered from this form Cat = trim(request("Cat")) if Cat = "" then error_list.add "484304","Category must be specified." b_error = true end if CatID = trim(request("CatID")) CatTypeId = trim(request("CatTypeId")) Description = trim(request("Description")) ParentId = trim(request("ParentId")) RelatedId = trim(request("RelatedId")) end sub sub validate_view_cats ''' request and validate data entered from this form Parent = trim(request("Parent")) ParentId = trim(request("ParentId")) CatID = trim(request("CatID")) Cat = trim(request("Cat")) RelatedId = trim(request("RelatedId")) CatType = trim(request("CatType")) end sub sub db_select_edit_Cats sql = "SELECT " & _ "Cat, " & _ "CatID, " & _ "CatTypeId, " & _ "Description, " & _ "ParentId, " & _ "RelatedId FROM Cats" & _ " WHERE " & _ "Cats.CatID = " & to_sql(CatID,"number") & "" on error resume next set rs = cn.Execute(sql) if err.number <> 0 then b_error = true error_list.add "select_data_edit_Cats", "The data selection failed. " & err.description elseif rs.EOF then b_results = false msg_list.add "select_data_edit_Cats", "The record was removed from the database." else Cat = rs("Cat") CatID = rs("CatID") CatTypeId = rs("CatTypeId") Description = rs("Description") ParentId = rs("ParentId") RelatedId = rs("RelatedId") end if rs.Close on error goto 0 end sub sub db_insert_edit_Cats sql = "INSERT INTO Cats" & _ "(" & _ "Cat," & _ "CatTypeId," & _ "Description," & _ "ParentId," & _ "RelatedId" & _ ") VALUES (" & to_sql(Cat,"text") & "," & _ "" & to_sql(CatTypeId,"number") & "," & _ "" & to_sql(Description,"text") & "," & _ "" & to_sql(ParentId,"number") & "," & _ "" & to_sql(RelatedId,"number") & ")" & _ "" 'response.write sql on error resume next cn.Execute(sql) if err.Number <> 0 then b_error = true error_list.add "db_insert_edit_Cats" & err.Number ,"The database insert failed. " & err.Description else set rs = cn.Execute("SELECT @@IDENTITY") CatID = rs(0) rs.Close msg_list.add "db_insert_edit_Cats","The database insert was successful." end if on error goto 0 end sub sub db_update_edit_Cats sql = "UPDATE Cats SET " & _ "Cat = " & to_sql(Cat,"text") & ", " & _ "CatTypeId = " & to_sql(CatTypeId,"number") & ", " & _ "Description = " & to_sql(Description,"text") & ", " & _ "ParentId = " & to_sql(ParentId,"number") & ", " & _ "RelatedId = " & to_sql(RelatedId,"number") & " WHERE " & _ "CatID = " & to_sql(CatID,"number") & "" 'response.write sql on error resume next cn.execute(sql) if err.number <> 0 then b_error = true error_list.add "db_update_edit_Cats" & err.Number ,"The database update failed. " & err.Description else msg_list.add "db_update_edit_Cats" & CatID,"The database update was successful." end if on error goto 0 end sub sub db_delete_edit_Cats sql = "DELETE FROM Cats" & _ " WHERE " & _ "CatID = " & to_sql(CatID,"number") & "" 'response.write sql on error resume next cn.Execute(sql) if err.number <> 0 then b_error = true error_list.add "db_delete_edit_Cats" & err.Number ,"The database deletion failed. " & err.Description else msg_list.add "db_delete_edit_Cats","The record was removed." end if on error goto 0 end sub sub db_select_view_Cats view_Cats_sql = "SELECT " & _ "Cats2.Cat As Parent," & _ "Cats.Cat, " & _ "Cats.CatID, " & _ "CatType, " & _ "CatTypes.CatTypeId, " & _ "Cats.ParentId, " & _ "Cats.RelatedId As RelatedId FROM ((CatTypes LEFT JOIN Cats ON Cats.CatTypeId=CatTypes.CatTypeId) LEFT JOIN Cats As Cats2 ON Cats2.CatId = Cats.ParentId) ORDER BY Cats2.Cat" if request("sortby") <> "" AND inStr(lcase(view_Cats_sql),"order by") = 0 then view_Cats_sql = view_Cats_sql + " ORDER BY " & request("sortby") end sub sub db_delete_view_Cats sql = "DELETE FROM " & _ "" 'response.write sql on error resume next cn.Execute(sql) if err.number <> 0 then b_error = true end if on error goto 0 end sub do_search = request("do_search") ''' request form keys CatID = request("CatID") ''' request action action = lcase(request("action")) ''' action case handler select case action case "select_edit_cats" ' select the requested key record from database if CatID <> "" then db_select_edit_Cats else b_error = true error_list.add "edit_edit_Cats", "Specify record to select." end if case "insert_edit_cats" ' request form data and insert a new record into database validate_edit_Cats db_insert_edit_Cats response.redirect request.servervariables("script_name") case "update_edit_cats" ' request form data and update an existing database record validate_edit_cats if not b_error then if CatID <> "" then db_update_edit_cats else b_error = true error_list.add "update_edit_cats", "Specify record to update." end if end if case "delete_edit_cats" ' delete the requested key database record if CatID <> "" then db_delete_edit_cats response.redirect request.servervariables("script_name") & "?msg=The+record+was+deleted." else b_error = true error_list.add "delete_edit_cats", "Specify record to delete." end if end select ' no action was specified, so handle the default case(s) if CatID <> "" then db_select_edit_cats end if db_select_view_cats %> <!-- #include file='i_header.asp' --> <!-- #include file='i_menu.asp' --> <!-- #include file="i_menu_admin.asp" --> <% display_errs display_msg %> <table class='headerTable'> <tr> <td class='headerTD'> <A href='admin_cats.asp'>Category Manager</A> </td> </tr> </table> <table > <form name="edit_Cats" action="admin_cats.asp" method="get" > <tr> <td class='labelTD'>Category</td> <td class='dataTD' > <input type=text name="Cat" size="" maxlength="50" value="<% =Cat%>"> </td> </tr> <input type=hidden name="CatID" value="<% =CatID %>"> <tr> <td class='labelTD'>Category Type <A href="admin_cattypes.asp">?</A></td> <td class='dataTD' > <select name="CatTypeId" > <option></option> <% =get_options ("SELECT CatTypeId,CatType FROM CatTypes", CatTypeId) %> </select> <A href="admin_cattypes.asp">define types</A>.. </td> </tr> <tr> <td class='labelTD'>Description</td> <td class='dataTD' > <textarea name="Description" rows='6' cols='50'><% =Description%></textarea> </td> </tr> <tr> <td class='labelTD'>Parent</td> <td class='dataTD' > <select name="ParentId" > <option></option> <% =get_options ("SELECT CatId,Cat FROM Cats", ParentId) %> </select> </td> </tr> <tr> <td class='labelTD'>Related</td> <td class='dataTD' > <select name="RelatedId" > <option></option> <% =get_options ("SELECT Cats3.CatId, Cats.Cat, Cats1.Cat, Cats2.Cat, Cats3.Cat FROM (((Cats As Cats3 left JOIN Cats As Cats2 ON Cats3.ParentId = Cats2.CatId) left JOIN Cats As Cats1 ON Cats2.ParentId = Cats1.CatId) LEFT JOIN Cats As Cats ON Cats1.ParentId = Cats.CatId) WHERE Cats.ParentId is NULL order by (Cats.Cat + Cats1.Cat + Cats2.Cat + Cats3.Cat)", RelatedId) %> </select> </td> </tr> <tr> <td class=labelTD align=right> <% if CatID <> "" then %><input type=button name=new_button value=new onclick="window.location = '<% =request.servervariables("script_name") %>'"><% end if %> </td> <td class=dataTD> <% if CatID = "" then %><input type=submit name=insert_button value=insert><% end if %> <% if CatID <> "" then %><input type=submit name=update_button value=update><% end if %> <% if CatID <> "" then %><input type=submit name=delete_button value=delete onclick="document.edit_Cats.action.value = 'delete_edit_Cats'"><% end if %> </td> <input type=hidden name="action" value="<% if CatID <> "" then %>update<% else %>insert<%end if %>_edit_Cats"></tr> </form> </table> <% page_no = request("page_no") if page_no = "" then page_no = 1 if view_Cats_sql <> "" then cmd.CommandText = view_Cats_sql rs.Filter = "" rs.CursorLocation = 3 rs.CacheSize = 5 rs.Open cmd if not rs.EOF then rs.MoveFirst rs.PageSize = 50 max_count = cInt(rs.PageCount) num_recs = rs.RecordCount rs.AbsolutePage = page_no results = true else results = false rs.Close end if else results = false end if rec_count = 0 %> <% if results = true then %> <table > <form name="view_Cats" action="admin_cats.asp" method="get" > <tr> <td class='fieldTD'><a href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no %>&sortby=CatID" class=fieldFont title="">CatID</a></td> <td class='fieldTD'><a href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no %>&sortby=Cat" class=fieldFont title="">Cat</a></td> <td class='fieldTD'><a href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no %>&sortby=RelatedId" class=fieldFont title="">Related To</a></td> <td class='fieldTD'><a href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no %>&sortby=CatType" class=fieldFont title="">Category Type</a></td> </tr> <% do while not rs.EOF AND (rec_count < rs.Pagesize) ':: read db record on error resume next Parent = rs("Parent") ParentId = rs("ParentId") CatID = rs("CatID") Cat = rs("Cat") RelatedId = rs("RelatedId") CatType = rs("CatType") on error goto 0 %> <% if lastgroup <> Parent OR (isnull(lastgroup) AND Parent <> "") then %><!-- group row --><tr> <td valign=top class=groupTD colspan=7> <% =Parent %><br> </td></tr><% end if %> <input type=hidden name="Parent" value="<% =Parent %>"> <input type=hidden name="ParentId" value="<% =ParentId %>"> <tr> <td class='dataTD' > <a href="admin_cats.asp?CatID=<%=CatID%>"><% =CatID %></a> </td> <td class='dataTD' > <a href="admin_cats.asp?CatID=<%=CatID%>"><% =Cat %></a> </td> <td class='dataTD' > <% =RelatedId %> </td> <td class='dataTD' > <% =CatType %> </td> </tr> <% lastgroup = Parent rs.MoveNext rec_count = rec_count + 1 loop rs.Close %> </form> </table> <% else %> <% end if %> <% if max_count > 1 then %> <!-- paging footer --> <TABLE class=HeaderTable > <tr> <td width="20%" class=HeaderTD> <% if page_no > 1 then %> <a class=HeaderFont href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no-1 %>&sortby=<% =request("sortby") %>">PREV</a> <% else %> <% end if %> </td> <td align=center class=HeaderTD> Page <% for i = 1 to max_count %> <% if i = cint(page_no) then %> <b><%=i%></b> <% else %> <a class=HeaderFont href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =i %>&sortby=<% =request("sortby") %>"><%=i%></a> <% end if %> <%next %> </td> <td align=right width="20%" class=HeaderTD> <% if cInt(page_no) < cInt(max_count) then %> <a class=HeaderFont href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no+1 %>&sortby=<% =request("sortby") %>">NEXT</a> <% end if %> </td> </tr> </TABLE> <% end if %> <!-- #include file=i_footer.asp --> <% ':: assure that any db resources are freed on error resume next rs.Close set rs = NOTHING cn.Close set cn = NOTHING user_cn.Close set user_cn = NOTHING on error goto 0 %>